home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d22 / getrom.arc / LSPLIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-30  |  1.0 KB  |  49 lines

  1. /* This program is designed to londitudinally split files.
  2.    It expects two arguments, the first argument specifies
  3.    the maximum length of the target files, and the second
  4.    the name of the source file.
  5.    The target files are named F0 -  Fn.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. main(argc,argv)
  10. int argc;
  11. char **argv;
  12. {
  13. int i, c, x;
  14. char fp[5];
  15. FILE *outfile, *infile;
  16. if (argc    != 3)
  17.     {
  18.     printf("Argument error");
  19.     exit(0);
  20.     }
  21. argv++;  /* get the maximum target file size */
  22. i = atoi(*argv);
  23. argv++;    /* get the source filename*/
  24. if ((infile = fopen(*argv, "rb")) == NULL)
  25.     {
  26.     perror("Can't open input file");
  27.     exit(0);
  28.     }
  29. fp[0] = 'F';
  30. fp[2] = 0;
  31. c = 0;
  32. for ((fp[1] = '0'); (((c = getc(infile)) != EOF)    && (fp[1] <= '9')); fp[1]++)
  33.     {
  34.     x = 2;
  35.     outfile = fopen(fp, "wb");
  36.     putc(c, outfile);
  37.     while ((x <= i) && ((c = getc(infile)) != EOF))
  38.         {
  39.         putc(c,outfile);
  40.         x++;
  41.         }
  42.     fclose(outfile);
  43.     }
  44. fclose(infile);
  45. if (fp[1] > '9')
  46.     printf("Warning - more than 9 files required");
  47. exit(0);
  48. }
  49.